package com.prj.ufdm.drools.config.controll;

import org.kie.api.runtime.KieSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.prj.ufdm.core.dto.RetData;
import com.prj.ufdm.drools.config.model.Address;
import com.prj.ufdm.drools.config.model.fact.AddressCheckResult;

@RestController
@RequestMapping("/drools")
public class AddressAction {

	@Autowired
	private KieSession kieSession;

    
    /**
     * 获取所有流程定义
     * @return
     * @throws Exception
     */
	@RequestMapping("/address")
    public RetData<String> getAddress() throws Exception {
    	RetData<String> retData = new RetData<String>();
    	
    	Address address = new Address();
        address.setPostcode("994251");

        AddressCheckResult result = new AddressCheckResult();
        kieSession.insert(address);
        kieSession.insert(result);
        int ruleFiredCount = kieSession.fireAllRules();
        System.out.println("触发了" + ruleFiredCount + "条规则");

        if(result.isPostCodeResult()){
            System.out.println("规则校验通过");
        }
   	
    	retData.setRetBody("");
    	
    	return retData;
    	
    }
}
 